package com.wlb.test.service.rabbitmq.topics;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wlb.test.util.rabbitmq.ConnectionUtil;
import com.wlb.test.util.rabbitmq.QueueEnum;

/**
 * @Author:wanglibing
 * @Mail:wanglibing@jd.com
 * @Date:Created in 16:51 2018/1/30
 * @Description:
 */
public class Send {
    public static void main(String[] args) throws Exception{
        // 获取到连接以及mq通道
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        // 声明exchange
        channel.exchangeDeclare(QueueEnum.EXCHANGE_NAME_TOPIC.getName(), "topic");

        // 消息内容
        String message = "id=1001";
        String message2 = "id=1111";
        channel.basicPublish(QueueEnum.EXCHANGE_NAME_TOPIC.getName(), "key.1", null, message.getBytes());
        channel.basicPublish(QueueEnum.EXCHANGE_NAME_TOPIC.getName(), "key.2", null, message2.getBytes());
        System.out.println(" [x] Sent '" + message + "'");
        System.out.println(" [x] Sent '" + message2 + "'");
        channel.close();
        connection.close();
    }
}
